package Common;

import com.liferay.portal.service.PortletLocalServiceUtil;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.model.Portlet;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import java.lang.System;

public class Portlet_Function {
	public static String getPortletIdByName(String portletName) {
		List<Portlet> list = PortletLocalServiceUtil.getPortlets();

		for (int i = 0; i < list.size(); i++) {
			try {
				if (list.get(i).getDisplayName().equalsIgnoreCase(portletName)) {
					return list.get(i).getPortletId();
				}
			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			// SessionMessages.add
		}
		return "";
	}

	private static Connection createConnection() {

		Connection con = null;

		String url = "jdbc:postgresql://192.168.1.26/DW";
		String user = "postgres";
		String password = "hue@1234";

		try {
			con = DriverManager.getConnection(url, user, password);

		} catch (SQLException ex) {

		}
		return con;
	}

	public static ResultSet executeQuery(String sSql) {
		Connection con = null;
		Statement st = null;
		ResultSet rs = null;
		try {
			con = createConnection();
			st = con.createStatement();
			rs = st.executeQuery(sSql);
			while(rs.next())
			{
				
			}
			return rs;
		} catch (SQLException ex) {
			System.out.println("Loi thuc thi cau lenh");
			return null;
		}
	}
}
